package coms.ejb;

import coms.dataaccess.dao.ConferenceRegistrationDAO;
import coms.dataaccess.hibernate.HibernateDAOFactory;
import coms.dto.Conference;
import coms.dto.ConferenceRegistration;
import coms.dto.User;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.ejb.Stateless;

@Stateless (mappedName="ConferenceRegistrationBean")
public class ConferenceRegistrationBean extends GenericBean<ConferenceRegistration> implements ConferenceRegistrationBeanRemote{
    
  private ConferenceRegistrationDAO conferenceRegistrationDAO;
    
    @PostConstruct
    public void construct() {
        super.construct();
        HibernateDAOFactory factory = new HibernateDAOFactory();
        conferenceRegistrationDAO = factory.getConferenceRegistrationDAO();
    }
    
    @Override
    public List<ConferenceRegistration> getByConference(Conference conference) {
          ConferenceRegistration confReg = new ConferenceRegistration();
          confReg.setConference(conference);
          List<ConferenceRegistration> confRegList = new ArrayList<ConferenceRegistration>();
        try {
            confRegList = conferenceRegistrationDAO.search(confReg);
        } catch (SQLException ex) {
            Logger.getLogger(ConferenceRegistrationBean.class.getName()).log(Level.SEVERE, null, ex);
        }
         return confRegList;
    }
    
    @Override
    public List<ConferenceRegistration> getByParticipant(User user) {
          ConferenceRegistration confReg = new ConferenceRegistration();
          confReg.setParticipant(user);
          List<ConferenceRegistration> confRegList = new ArrayList<ConferenceRegistration>();
        try {
            confRegList = conferenceRegistrationDAO.search(confReg);
        } catch (SQLException ex) {
            Logger.getLogger(ConferenceRegistrationBean.class.getName()).log(Level.SEVERE, null, ex);
        }
         return confRegList;
    }
    
}